package cn.ibizlab.odoo.core.odoo_survey.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line;
import cn.ibizlab.odoo.core.odoo_survey.domain.Survey_user_input_line;
import cn.ibizlab.odoo.core.odoo_survey.filter.Survey_user_input_lineSearchContext;
import cn.ibizlab.odoo.core.odoo_survey.service.ISurvey_user_input_lineService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[调查用户输入明细] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Survey_user_input_lineServiceImpl implements ISurvey_user_input_lineService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Isurvey_user_input_lineClientService survey_user_input_lineClientService;

    @Override
    public void createBatch(List<Survey_user_input_line> survey_user_input_lines, int batchSize) {

                        //survey_user_input_lineClientService.createBatch(survey_user_input_lines,batchSize) ;

    }

    @Override
    public boolean update(Survey_user_input_line survey_user_input_line) {
        boolean bOk = false ;
        Isurvey_user_input_line clientModel = this.convert2Model(survey_user_input_line,null);
        survey_user_input_lineClientService.update(clientModel) ;
        this.convert2Domain(clientModel,survey_user_input_line) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //survey_user_input_lineClientService.removeBatch(survey_user_input_lines) ;

    }

    @Override
    public void updateBatch(List<Survey_user_input_line> survey_user_input_lines, int batchSize) {

        //survey_user_input_lineClientService.updateBatch(survey_user_input_lines,batchSize) ;

    }

    @Override
    public Survey_user_input_line get(Integer id) {
        Isurvey_user_input_line clientModel = survey_user_input_lineClientService.createModel();
        clientModel.setId(id);
        survey_user_input_lineClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Survey_user_input_line get(Survey_user_input_line survey_user_input_line) {
        Survey_user_input_line retsurvey_user_input_line = this.get(survey_user_input_line.getId()) ;
    	BeanCopier copier=BeanCopier.create(retsurvey_user_input_line.getClass(), survey_user_input_line.getClass(), false);
        copier.copy(retsurvey_user_input_line, survey_user_input_line, null);
        return survey_user_input_line ;
    }

    @Override
    public boolean create(Survey_user_input_line survey_user_input_line) {
        boolean bOk = false ;
        Isurvey_user_input_line clientModel = this.convert2Model(survey_user_input_line,null);
        survey_user_input_lineClientService.create(clientModel) ;
        this.convert2Domain(clientModel,survey_user_input_line);
        bOk = true ;

        return bOk ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Isurvey_user_input_line clientModel = survey_user_input_lineClientService.createModel();
        clientModel.setId(id);
        survey_user_input_lineClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Survey_user_input_line> searchDefault(Survey_user_input_lineSearchContext context) {
        List<Survey_user_input_line> list = new ArrayList<Survey_user_input_line>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line> clientModelList = survey_user_input_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input_line>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据用户查询
     */
    @Override
    public Page<Survey_user_input_line> selectByOdoo_create(Integer id){
        Survey_user_input_lineSearchContext context = new Survey_user_input_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_user_input_line> list = new ArrayList<Survey_user_input_line>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line> clientModelList = survey_user_input_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Survey_user_input_line> selectByOdoo_write(Integer id){
        Survey_user_input_lineSearchContext context = new Survey_user_input_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_user_input_line> list = new ArrayList<Survey_user_input_line>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line> clientModelList = survey_user_input_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据调查标签查询
     */
    @Override
    public Page<Survey_user_input_line> selectByOdoo_value(Integer id){
        Survey_user_input_lineSearchContext context = new Survey_user_input_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_user_input_line> list = new ArrayList<Survey_user_input_line>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line> clientModelList = survey_user_input_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据调查标签查询
     */
    @Override
    public Page<Survey_user_input_line> selectByOdoo_value_suggested(Integer id){
        Survey_user_input_lineSearchContext context = new Survey_user_input_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_user_input_line> list = new ArrayList<Survey_user_input_line>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line> clientModelList = survey_user_input_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据调查问题查询
     */
    @Override
    public Page<Survey_user_input_line> selectByOdoo_question(Integer id){
        Survey_user_input_lineSearchContext context = new Survey_user_input_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_user_input_line> list = new ArrayList<Survey_user_input_line>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line> clientModelList = survey_user_input_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据问卷查询
     */
    @Override
    public Page<Survey_user_input_line> selectByOdoo_survey(Integer id){
        Survey_user_input_lineSearchContext context = new Survey_user_input_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_user_input_line> list = new ArrayList<Survey_user_input_line>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line> clientModelList = survey_user_input_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据调查用户输入查询
     */
    @Override
    public Page<Survey_user_input_line> selectByOdoo_user_input(Integer id){
        Survey_user_input_lineSearchContext context = new Survey_user_input_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_user_input_line> list = new ArrayList<Survey_user_input_line>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line> clientModelList = survey_user_input_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Isurvey_user_input_line convert2Model(Survey_user_input_line domain , Isurvey_user_input_line model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = survey_user_input_lineClientService.createModel() ;
        }

         if(domain.getValue_dateDirtyFlag())
            model.setValue_date(domain.getValue_date());
         if(domain.getValue_free_textDirtyFlag())
            model.setValue_free_text(domain.getValue_free_text());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getDate_createDirtyFlag())
            model.setDate_create(domain.getDate_create());
         if(domain.getSkippedDirtyFlag())
            model.setSkipped(domain.getSkipped());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getQuizz_markDirtyFlag())
            model.setQuizz_mark(domain.getQuizz_mark());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getAnswer_typeDirtyFlag())
            model.setAnswer_type(domain.getAnswer_type());
         if(domain.getValue_textDirtyFlag())
            model.setValue_text(domain.getValue_text());
         if(domain.getValue_numberDirtyFlag())
            model.setValue_number(domain.getValue_number());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getPage_idDirtyFlag())
            model.setPage_id(domain.getPage_id());
         if(domain.getUser_input_idDirtyFlag())
            model.setUser_input_id(domain.getUser_input_id());
         if(domain.getValue_suggestedDirtyFlag())
            model.setValue_suggested(domain.getValue_suggested());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getValue_suggested_rowDirtyFlag())
            model.setValue_suggested_row(domain.getValue_suggested_row());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getQuestion_idDirtyFlag())
            model.setQuestion_id(domain.getQuestion_id());
         if(domain.getSurvey_idDirtyFlag())
            model.setSurvey_id(domain.getSurvey_id());
        return model ;
    }

    public Survey_user_input_line convert2Domain( Isurvey_user_input_line model ,Survey_user_input_line domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Survey_user_input_line();
        }

        if(model.getValue_dateDirtyFlag())
            domain.setValue_date(model.getValue_date());
        if(model.getValue_free_textDirtyFlag())
            domain.setValue_free_text(model.getValue_free_text());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getDate_createDirtyFlag())
            domain.setDate_create(model.getDate_create());
        if(model.getSkippedDirtyFlag())
            domain.setSkipped(model.getSkipped());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getQuizz_markDirtyFlag())
            domain.setQuizz_mark(model.getQuizz_mark());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getAnswer_typeDirtyFlag())
            domain.setAnswer_type(model.getAnswer_type());
        if(model.getValue_textDirtyFlag())
            domain.setValue_text(model.getValue_text());
        if(model.getValue_numberDirtyFlag())
            domain.setValue_number(model.getValue_number());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getPage_idDirtyFlag())
            domain.setPage_id(model.getPage_id());
        if(model.getUser_input_idDirtyFlag())
            domain.setUser_input_id(model.getUser_input_id());
        if(model.getValue_suggestedDirtyFlag())
            domain.setValue_suggested(model.getValue_suggested());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getValue_suggested_rowDirtyFlag())
            domain.setValue_suggested_row(model.getValue_suggested_row());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getQuestion_idDirtyFlag())
            domain.setQuestion_id(model.getQuestion_id());
        if(model.getSurvey_idDirtyFlag())
            domain.setSurvey_id(model.getSurvey_id());
        return domain ;
    }


}
